package com.jn.algorithm.other;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 江南大学1033190417
 * @date 2022/5/11 17:05
 */

//计算表达式的值
public class Solution {

    public static Map<Character, Integer> map = new HashMap<Character, Integer>() {{
        put(')', -1);
        put('+', 1);
        put('-', 1);
        put('*', 2);
        put('(', 2);
    }};

    //符号的优先级
    /*
       )
       +  -
       *  /
       (
     */
    public int expression(String s) {
        Deque<Integer> num = new ArrayDeque<>();
        Deque<Character> fuhao = new ArrayDeque<>();
        int id = 0;
        int n = s.length();
        while (id < n) {
            char now = s.charAt(id);
            if (now - '0' >= 0 && now - '0' <= 9) {//如果是数字
                num.addLast(now - '0');
            } else {//如果是运算符
                if (fuhao.isEmpty()) {//如果符号栈是空，直接入栈
                    fuhao.addLast(now);
                } else {
                    Character peek = fuhao.peek();
                    int p1 = map.get(peek);
                    int p2 = map.get(now);
                    if (p2 > p1) {
                        fuhao.addLast(now);
                    } else {
                        if (peek=='('&&now!=')'){
                            fuhao.addLast(now);
                        }else if (peek=='('&&now==')'){
                            fuhao.pop();
                        }
                    }
                }
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        String s1=new StringBuilder("go").append("od").toString();
       // System.out.println(s1==s1.intern());
        s1.intern();
        System.out.println("good" == s1);
    }
}
